load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

idl_generator(
    name = "execution_control_parameters_gen",
    src = "execution_control_parameters.idl",
)

idl_generator(
    name = "throughput_probing_gen",
    src = "throughput_probing.idl",
)

idl_generator(
    name = "execution_control_heuristic_parameters_gen",
    src = "execution_control_heuristic_parameters.idl",
)

mongo_cc_library(
    name = "execution_control_stats",
    srcs = [
        "execution_control_stats.cpp",
    ],
    hdrs = [
        "execution_control_stats.h",
    ],
    deps = [
        "//src/mongo:base",
    ],
)

mongo_cc_library(
    name = "ticketing_system",
    srcs = [
        "execution_control_parameters_gen",
        "throughput_probing.cpp",
        "throughput_probing_gen",
        "ticketing_system.cpp",
    ],
    no_undefined_ref_DO_NOT_USE = False,
    deps = [
        "//src/mongo/db:server_base",
        "//src/mongo/db/commands:test_commands_enabled",
        "//src/mongo/util:processinfo",
        "//src/mongo/util/concurrency:ticketholder",
    ],
)

mongo_cc_library(
    name = "execution_admission_context",
    srcs = [
        "execution_admission_context.cpp",
        "execution_control_heuristic_parameters_gen",
    ],
    deps = [
        ":execution_control_stats",
        "//src/mongo/db:server_base",
        "//src/mongo/util/concurrency:admission_context",
    ],
)

mongo_cc_unit_test(
    name = "throughput_probing_test",
    srcs = [
        "throughput_probing_test.cpp",
    ],
    tags = ["mongo_unittest_sixth_group"],
    deps = [
        ":ticketing_system",
        "//src/mongo/db:service_context",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/db:shard_role_api",
        "//src/mongo/db/shard_role/lock_manager",
        "//src/mongo/transport:transport_layer_common",
        "//src/mongo/unittest",
        "//src/mongo/util:mock_periodic_runner",
        "//src/mongo/util/concurrency:ticketholder",
    ],
)

# TODO(SERVER-96853): Remove cycle created by moving //src/mongo/db:execution_admission_context.h to //src/mongo/db/admission/execution_control:execution_admission_context
filegroup(
    name = "execution_admission_context_hdrs",
    srcs = [
        ":execution_admission_context.h",
        ":execution_control_stats.h",
    ],
)
